﻿using NFine.Code;
using NFine.Data;
using NFine.Domain.Entity.BusinessManage;
using NFine.Domain.Entity.SystemManage;
using NFine.Domain.IRepository.BusinessManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace NFine.Repository.BusinessManage
{
    public class D_MemberChargeRepository : RepositoryBase<D_MemberCharge>, ID_MemberCharge
    {
        public List<D_SalaryHistoryEntity> GetAllSaleGrid(Expression<Func<D_SalaryHistoryEntity, bool>> expressionS, Expression<Func<UserEntity, bool>> expressionU1, Pagination pagination)
        {
            using (var db = new RepositoryBase())
            {
                var query = from sh in db.DbSet<D_SalaryHistoryEntity>().Where(expressionS)
                            join u1 in db.DbSet<UserEntity>().Where(expressionU1) on sh.UserID equals u1.F_Id
                            join u2 in db.DbSet<UserEntity>() on sh.TriggerUserID equals u2.F_Id
                            orderby sh.TriggerTime descending
                            select new { sh, u1, u2 };
                List<D_SalaryHistoryEntity> lst = new List<D_SalaryHistoryEntity>();
                foreach (var obj in query)
                {
                    obj.sh.Account = obj.u1.F_Account;
                    obj.sh.AccountName = obj.u1.F_RealName;
                    obj.sh.TAccount = obj.u2.F_Account;
                    obj.sh.TAccountName = obj.u2.F_RealName;
                    lst.Add(obj.sh);
                }
                return lst;
            }
        }
    }
}